#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/mman.h>
#include<errno.h>
#include<fcntl.h>
#include<unistd.h> 
#include<pthread.h>


struct STUDENT{
	char name[256];
	int id;
	int source;
};



int
main(int argc, char* args[])
{
	int fd;
	fd = open("mmap", O_RDWR | O_CREAT, 0644);
	if(fd < 0){
		perror("open error");
		exit(1);
	}
	
	ftruncate(fd, sizeof(STUDENT));
	struct STUDENT* mm = nullptr;
	//struct STUDENT* mm;
	mm = (STUDENT*) mmap(NULL, sizeof(STUDENT), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
	
	struct STUDENT student = {"张旋", 1, 0};
	while(1){
		memcpy(mm, &student, sizeof(student));
		++ student.id;
		sleep(1);
	}

	mnumap(mm, sizeof(student));
	return 0;
}
